package com.vcredit.creditcat.manager.emall;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.vcredit.bird.service.base.BirdResponse;
import com.vcredit.bird.service.emall.TaobaoProcessService;
import com.vcredit.creditcat.api.ITaoBaoProcessManager;
import com.vcredit.creditcat.dto.emallcredit.TaobaoProcessInDto;
import com.vcredit.creditcat.enumtype.EMStatusEnum;
import com.vcredit.creditcat.model.AuthTaobao;
import com.vcredit.creditcat.model.Cust;
import com.vcredit.creditcat.service.AuthTaobaoService;
import com.vcredit.creditcat.util.Constants;
import com.vcredit.framework.annotation.Log;

@Service(protocol = { "protocol1" }, version = "1.0")
public class TaobaoProcessManager implements ITaoBaoProcessManager {
	@Autowired
	private TaobaoProcessService taobaoProcessService;
	@Autowired
	private AuthTaobaoService authTaobaoService;

	@Log
	public void login(TaobaoProcessInDto param, Cust cust) throws Exception {
		BirdResponse initResult = taobaoProcessService.taobaoInit();
		String token = initResult.getToken();
		taobaoProcessService.taobaoLogin(param.getUserName(), param.getPassword(), cust.getCustName(),
				cust.getCustIdno(), param.getCookies(), token, Constants.TAOBAO_BUSTYPE);
		AuthTaobao authTaobao = new AuthTaobao(cust.getLastProccessId(), token, EMStatusEnum.CRAWING.getCode());
		authTaobao.setExpiredTime("");
		authTaobao.setCust(cust);
		authTaobaoService.updateCreditTaobao(authTaobao);
	}

	public void updateCrawlStatus(AuthTaobao authTaobao) throws Exception {
		authTaobaoService.updateCreditTaobao(authTaobao);
	}

	public List<AuthTaobao> findUnCrawl() {
		return authTaobaoService.findUnCrawl();
	}
}
